/*
 * @Author: your name
 * @Date: 2021-09-09 15:15:07
 * @LastEditTime: 2021-11-09 11:11:50
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \shanzhong-be\lib\routes\statistic.js
 */
const express = require('express');
const router = express.Router();
const outer = require('../handler/summary');
const stat = require('../handler/statistic');

// 图表数据分析接口
router.get('/chart-data', async(req, res) => {
  const data = await outer.getChartData(req.query);
  res.send(data);
});

// 导出数据
router.get('/excel', async(req, res) => {
  const {result, filename}= await stat.exportData(req.query);
  // console.log(data, '000');
  // console.log(result, mimeType, filename);
  res.setHeader('Access-Control-Expose-Headers', 'Content-Disposition');
  res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  res.setHeader('Content-Disposition', filename);
  res.end(result, 'binary');
  // res.download('./public/text.xlsx');
  // res.send();
});

module.exports = router;